@extends('admin.layouts._menu')
@section('content')
    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-overflow header-tabs">
                <li class="nav-item">
                    <a href="{{route('admin.category.index')}}" class="nav-link pb-3 active">
                        分类列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{route('admin.category.create')}}" class="nav-link pb-3">
                        添加分类
                    </a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <table class="table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>栏目名称</th>
                    <th>父级分类名称</th>
                    <th>图标</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($categories as $category)
                    {{--@dd($category);--}}
                    <tr>
                        <td scope="row">{{$category->id}}</td>
                        <td>{{$category['title']}}</td>
                        <td>
                            @if($category['parent_id']==0)
                                顶级分类
                            @else
                               {{$category->parentName->title}}
                                @endif
                        </td>
                        <td>
                                <i class="{{$category['icon']}}"></i>
                        </td>
                        <td>{{$category->created_at}}</td>
                        <td >
                            <div class="btn-group btn-group-sm" role="group" aria-label="First group">
                                {{--<a href="article/{{$v['id']}}/edit" class="btn btn-white">修改</a>--}}
                                <a href="{{route('admin.category.edit',$category)}}" class="btn btn-light">编辑栏目</a>
                                <button type="button" class="btn btn-white" onclick="del(this)">删除栏目</button>
                                <form action="{{route('admin.category.destroy',$category)}}" method="post">
                                    @csrf @method('DELETE')
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                <td>{{$categories->links()}}</td>
                </tbody>
            </table>
        </div>
    </div>
    @endsection
  @push('js')
      <script>
          function del(e) {
              if (confirm('确定删除吗？')){
                  $(e).next().submit();
              }
          }
      </script>
      @endpush
